package integrated

import (
	"encoding/json"
	"reflect"
	"talent.com/agency_im/common/pay"
)

type baseMessageFrame struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}
type selectPayTypeMsg struct {
	PayType pay.PayType `json:"payType"`
}

type getPayTypeDetailMsg struct {
	ReceiptAddressID int         `json:"receiptAddressId"`
	PayType          pay.PayType `json:"payType"`
	PayUrl           string      `json:"payUrl"`
}

type getPayTypeAmountLevelsMsg struct {
	ReceiptAddressID  int         `json:"receiptAddressId"`
	PayType           pay.PayType `json:"payType"`
	Quotas            []int64     `json:"quotas"`
	AmountAllowCustom bool        `json:"amountAllowCustom"`
	AmountMin         int64       `json:"amountMin"`
	AmountMax         int64       `json:"amountMax"`
	AmountUnit        int64       `json:"amountUnit"`
}

type selectPayAmountMsg struct {
	ReceiptAddressID int         `json:"receiptAddressId"`
	PayType          pay.PayType `json:"payType"`
	Amount           int64       `json:"amount"`
}

type getPayOrderDetailMsg struct {
	OrderID          uint64      `json:"orderId"`
	ReceiptAddressID int         `json:"payTypeId"`
	PayType          pay.PayType `json:"payType"`
	PayUrl           string      `json:"payUrl"`
}

const (
	MsgTypeSelectPayType          = "pay:select_pay_type"            // 选择充值大分类
	MsgTypeGetPayTypeAmountLevels = "pay:get_pay_type_amount_levels" // 发送充值金额档位
	MsgTypeGetPayTypeDetail       = "pay:get_pay_type_detail"        // 发送收款方式详情
	MsgTypeSelectPayAmount        = "pay:select_pay_amount"          // 确定充值金额
	MsgGetPayOrderDetail          = "get_pay_order_detail"           // 查询支付订单
)

var msgTypeMap = map[reflect.Type]string{
	reflect.TypeOf(selectPayTypeMsg{}):          MsgTypeSelectPayType,
	reflect.TypeOf(getPayTypeDetailMsg{}):       MsgTypeGetPayTypeDetail,
	reflect.TypeOf(getPayTypeAmountLevelsMsg{}): MsgTypeGetPayTypeAmountLevels,
	reflect.TypeOf(selectPayAmountMsg{}):        MsgTypeSelectPayAmount,
	reflect.TypeOf(getPayOrderDetailMsg{}):      MsgGetPayOrderDetail,
}

func decodeMsgData(rawData json.RawMessage, data interface{}) (err error) {
	err = json.Unmarshal([]byte(rawData), data)
	return err
}

//func encodePayMsg(payMsg *baseMessageFrame) (string, error) {
//	if bytes, err := json.Marshal(payMsg); err != nil {
//		return "", err
//	} else {
//		return string(bytes), nil
//	}
//}
